//输出用户浏览过的品牌
#include<iostream> 
#include<vector>
#include<fstream>
#include<string>
using namespace std;	

const int t1=0.2;//5月
const int t2=0.3;//6月
const int t3=0.4;//7月
const int t4=0.6;//8月

const int o1=0.2;//点击
const int o2=0.3;//收藏
const int o3=0.5;//购买
const int o4=0.8;//购物车

struct node
{
    vector<string> ali;
    node *next;
};

ifstream fin;
fstream fout;
bool getitem(string temp[]);
int main()
{
    fin.open("/home/pi/code/al/ubotali.txt");
    node *head;
    node *tail;
    node *t;
    string temp[4];
    getitem(temp);
    head=new node;
    head->ali.push_back(temp[0]);
    head->ali.push_back(temp[1]);
    tail=t=head;
    while(true)
    {
	int i=getitem(temp);
	if(i==0)
	{
	    if(temp[0]==tail->ali[0])
	    {
		if(temp[1]==tail->ali.at(tail->ali.size()-1))
		{
		    continue;
		}
		else
		{
		    tail->ali.push_back((temp[1]));
		}
	    }
	    else
	    {
		t=new node;
		t->ali.push_back(temp[0]);
		t->ali.push_back(temp[1]);
		tail->next=t;
		tail=t;
		tail->next=NULL;
	    }
	}
	else 
	    break;
    }
    fin.close();
    fout.open("/home/pi/code/al/ub.txt",ios_base::out|ios_base::app);
    for(t=head;t!=NULL;t=t->next)
    {
	vector<string>::iterator x=t->ali.begin();
	fout<<*x<<"\t";
	for(x=t->ali.begin()+1;x!=t->ali.end();x++)
	    fout<<*x<<",";
	fout<<"e"<<endl;
    }
    fout.close();
}	
bool getitem(string temp[])
{
    if(fin.is_open()&&!fin.eof()){
	for(int i=0;i<4;i++)
	    fin>>temp[i];
	return 0;
    }
    else
	return 1;
}
